package kafka_model_apps

import java.sql.{Connection, DriverManager}

object myConn {
    private var connection: Connection = null
    private val driver = "com.mysql.cj.jdbc.Driver"
    private val url = "jdbc:mysql://localhost:3306/fp?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true&characterEncoding=utf-8"
    private val username = "root"
    private val password = "admin"

    def conn(): Connection = {
        if (connection == null) {
            println(this.driver)
            Class.forName(this.driver)
            try {
                connection = DriverManager.getConnection(url, username, password)
            } catch {
                case e: Exception =>
                    println(e.getMessage + "---------------" + e.getCause)
            }
        }
        connection
    }
}
